import os
import subprocess

import tkinter as tk
from tkinter import filedialog

from Utils.CmdResUtils import dealWithRes


def selectDisk():
    # 调用 wmic 命令获取盘符和磁盘的物理地址
    word_of_disk = dealWithRes(subprocess.check_output("wmic logicaldisk get name", shell=True, text=True))
    return word_of_disk


def open_with_explorer():
    """
       打开资源管理器并获取保存路径。

       Returns:
           str: 选择的保存路径,如果用户取消操作则返回 None。
       """
    root = tk.Tk()
    root.withdraw()  # 隐藏 Tkinter 主窗口

    save_path = filedialog.askdirectory()

    if save_path:
        return save_path
    else:
        return None


def mkdir(path: str, name: str):
    subprocess.check_output('cd /d \"' + path + "\" && " + 'mkdir \"' + name + "\"",
                            shell=True, universal_newlines=True)


def mk_file(path: str, name: str):
    subprocess.check_output('cd /d \"' + path + "\" && " + 'type nul > \"' + name + "\"", shell=True,
                            universal_newlines=True)


if __name__ == '__main__':
    mk_file("E:\\", "111.txt")
